﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Churchtoolkit.Utils.MVP;
using Churchtoolkit.Utils.Authentication;
using Churchtoolkit.DataAccess.Repositories;
using Churchtoolkit.DataAccess.Entities;
using Churchtoolkit.Utils.Navigation;

namespace Churchtoolkit.Web.Shell.Presenters
{
    public class ChangePasswordPresenter : Presenter
    {
        private IAuthentication _authentication;
        private MembersRepository _membersRepository;
        public ChangePasswordPresenter(IAuthentication authentication, MembersRepository membersRepository)
        {
            _authentication = authentication;
            _membersRepository = membersRepository;
        }

        public bool IsOldPasswordValid(string oldPassword)
        {
            Members member = _membersRepository.Find(m => m.MemberId = _authentication.CurrentLogedInMember.Id).Single();
            return member.Password == oldPassword;
        }

        public void ChangeToNewPassword( string newPassword)
        {
            Members member;
            member = _membersRepository.Find(m => m.MemberId = _authentication.CurrentLogedInMember.Id).Single();
            member.Password = newPassword;
            _membersRepository.Update(member);
           // Navigator.NavigateTo(Pages.Shared_Message, "code=0001");
            Navigator.NavigateTo(Pages._Default);      
        }
    }
}
